package com.baomidou.mybatisplus.samples.quickstart.controller;

import com.baomidou.mybatisplus.samples.quickstart.dao.UserDao;
import com.baomidou.mybatisplus.samples.quickstart.entity.User;
import com.sanbi.common.vo.ResponseVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("user")
@RestController
public class UserController {
    @Resource
    private UserDao userDao;

    @PostMapping("add")
    public ResponseVo<String> add(@RequestBody User user) {
        boolean flag=userDao.save(user);

        String msg=String.format("用户添加成功: %s",user);
        if(flag){
            return ResponseVo.ok(msg);
        }else {
            msg=String.format("用户添加失败: %s",user);
            return ResponseVo.fail(msg);
        }
    }

    @GetMapping("list")
    public ResponseVo<List<User>> list() {
        return ResponseVo.ok(userDao.list());
    }
}
